package org.tity.test.concurrent;

import org.tity.commons.network.Ajax;

public class ThreadInterrupt extends Thread 
{ 
    public void run() 
    { 
        try 
        { 
//            sleep(50000);  // 延迟50秒 
        	int i=0;
			 while(true)
			 {
				 i++;
				 String x=Ajax.get("http://www.baidu.com?wd="+System.currentTimeMillis());
				 System.out.println(i);
				 if(i>1000) break;
				 
			 }
        } 
        catch (Exception e) 
        { 
            System.out.println(e.getMessage()); 
        } 
    } 
    public static void main(String[] args) throws Exception 
    { 
        Thread thread = new ThreadInterrupt(); 
        thread.start(); 
        System.out.println("在50秒之内按任意键中断线程!"); 
        System.in.read(); 
        thread.interrupt(); 
        thread.join(); 
        System.out.println("线程已经退出!"); 
    } 
} 
